home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: updateEndOfLog.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:50 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "latch.h"
- #include "link.h"
- #include "lsn.h"
- #include "bf.h"
- #include "volume.h"
- #include "openlog.h"
- #include "trans.h"
- #include "logrecs.h"
- #include "threadstate.h"
- #include "util_funcs.h"
- #include "log_extfuncs.h"
- #include "log_intfuncs.h"
- #include "thread_funcs.h"
- #include "thread_globals.h"
- #include "log_globals.h"
-
- /*
- * Atomically make the new client log page the end of the
- * log. The end of the log points to empty space on the
- * end of the client log page. The log latch and semaphore are
- * also released.
- */
-
- FORCEMARK
- updateEndOfLog (
-
- TRANSREC *transRec,
- GROUPLINK *tailLink,
- SHORTPID tailPid,
- LSNOFFSET tailLSN,
- LSN *firstLSN, /* first log record in page */
- LSN *lastLSN, /* last log record in page */
- int logCount /* number of log records in page*/
- )
- {
-
- register OPENLOG *openLog;
- FORCEMARK forceMark;
-
- TRPRINT(TR_LOG, TR_LEVEL_1, ("last lsn:%d", lastLSN->offset));
-
- /*
- * get a register pointer to the openlog structure
- */
- openLog = &OpenLog;
-
- /*
- * check the open log magic number
- */
- CHECK_OPENLOG_MAGIC(openLog);
-
- /*
- * check the transaction magic number
- */
- CHECK_TRANSREC_MAGIC(transRec);
-
- /*
- * check to see if this is the first record for this transaction
- */
- if (transRec->logRecordCount == 0) {
-
- /*
- * record this as the first log record
- */
- transRec->firstLogPid = LSN_TO_LOG_PAGE(firstLSN->offset, openLog);
- transRec->logUnique = openLog->logRecordCount + 1;
- if (transRec->firstLSN.offset == NULL_LSN) transRec->firstLSN = *firstLSN;
- TRPRINT(TR_LOG, TR_LEVEL_2, ("first log record for tid:%d", firstLSN->offset));
-
- /*
- * check to see if the log queue is empty
- */
- if (LIST_EMPTY( &(openLog->activeList) )) {
-
- /*
- * this is the new last page
- */
- openLog->activePid = transRec->firstLogPid;
- openLog->activeUnique = transRec->logUnique;
- openLog->activeLSN = firstLSN->offset;
- TRPRINT(TR_LOG, TR_LEVEL_2, ("new first active log rec:%d", openLog->activeLSN));
- }
-
- /*
- * hang the transaction record off the log ordering list
- */
- listEnq( &(openLog->activeList), &(transRec->logActiveList) );
- }
-
- /*
- * increment the counter for this transaction
- */
- openLog->logRecordCount += logCount;
- forceMark = openLog->logRecordCount;
- TRPRINT(TR_LOG, TR_LEVEL_2, ("forceMark:%d", forceMark));
-
- /*
- * adjust log tail information
- */
- openLog->tailPid = tailPid;
- openLog->tailLSN = tailLSN;
- openLog->tailLink = tailLink;
- openLog->tailBuffer = tailLink->pageHash;
-
- /* Record the next LSN to be generated */
- openLog->nextValidLSN.wrapCount = openLog->wrapCount;
- openLog->nextValidLSN.offset =
- FIRST_LSN_ON_PAGE(openLog->tailLSN, openLog);
-
- /*
- * record this record as the last record
- * for backwards undo processing. The nextUndoLSN is equal to
- * the lastLSN since the record is not a compensation log record
- */
- transRec->lastLSN = lastLSN->offset;
- transRec->nextUndoLSN = lastLSN->offset;
-
- /*
- * give the log latch back
- */
- signalLatch( &(openLog->logLatch) );
- signalSemaphore( &(openLog->writeSemaphore) );
-
- /*
- * increment the checkpoint count
- */
- openLog->checkPointCount += logCount;
-
- /* increment the number of records written by the transaction */
- transRec->logRecordCount += logCount;
-
- /*
- * record the log space used by this trans
- * We assume it was the entire page since there may be
- * fragmentation during undo as well
- */
- ActiveLogSpace += openLog->pageSize;
- transRec->logSpace += openLog->pageSize;
-
- /*
- * return the log count
- */
- return(forceMark);
- }
-